﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnrealDebugger
{
    using System;
    using System.Collections.Generic;

    [Serializable]
    public class MultiMap<Key, Value>
    {
        SerializableDictionary<Key, List<Value>> _dictionary = new SerializableDictionary<Key, List<Value>>();

        public SerializableDictionary<Key, List<Value>> Dictionary
        {
            get { return _dictionary; }
            set { _dictionary = value; }
        }

        public void Add(Key key, Value value)
        {
            List<Value> list;
            if (this._dictionary.TryGetValue(key, out list))
            {
                list.Add(value);
            }
            else
            {
                list = new List<Value>();
                list.Add(value);
                this._dictionary[key] = list;
            }
        }

        public IEnumerable<Key> Keys
        {
            get
            {
                return this._dictionary.Keys;
            }
        }

        public List<Value> this[Key key]
        {
            get
            {
                List<Value> list;
                if (this._dictionary.TryGetValue(key, out list))
                {
                    return list;
                }
                else
                {
                    return new List<Value>();
                }
            }
        }
    }
}
